const state = {
  current: {},    // 当前用户
  userDeptList: {},    //用户可操作科室列表
  deptBudget: {},    //科室预算
  userState: {},    //用户操作状态
  dataviewMap: {},    //数据视图配置 {viewKey: 视图配置}
}

const getters = {
  currentUser: state => state.current,

  //用户可操作科室列表
  userDeptList: state => state.userDeptList,

  //科室预算
  deptBudget: state => state.deptBudget,
  //科室预算
  userState: state => state.userState,

}

const mutations = {
  SET_CURRENT_USER: (state, user) => {
    state.current = user
    if (user.token) {
      sessionStorage.setItem('Authorization', user.token)
    } else {
      state.current.token = sessionStorage.getItem('X-Token')
    }
  },
  SET_CURRENT_USER_DEPTLIST: (state, userDeptList) => {
    state.userDeptList = userDeptList
  },
  SET_CURRENT_USER_BUDET: (state, deptBudget) => {
    state.deptBudget = deptBudget
  },
  SET_CURRENT_USER_State: (state, userState) => {
    state.userState = userState
  },
  SET_DATAVIEW_MAP: (state, dataviewMap) => {
    state.dataviewMap = dataviewMap
  }
}

const actions = {
  setCurrentUser: (context, user) => context.commit('SET_CURRENT_USER', user),
  setCurrentUserDeptList: (context, userDeptList) => context.commit('SET_CURRENT_USER_DEPTLIST', userDeptList),
  setDeptBudget: (context, deptBudget) => context.commit('SET_CURRENT_USER_BUDET', deptBudget),
  seUserState: (context, userState) => context.commit('SET_CURRENT_USER_State', userState),
  seDataviewMap: (context, dataviewMap) => context.commit('SET_DATAVIEW_MAP', dataviewMap),
}

export default {
  state,
  getters,
  mutations,
  actions
}
